package com.fifth.business.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fifth.business.mapper.BusinessMapper;
import com.fifth.business.service.PersonService;
import com.fifth.business.untils.WebUtils;
import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.BusinessInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Service
public class PersonServiceImpl implements PersonService {

    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;




    /**
     * 修改密码
     * @param businessInfo
     * @return
     */
    @Override
    public CommonResult updatePassword(BusinessInfo businessInfo) {
        QueryWrapper wrapper = new QueryWrapper();
        Object password = wrapper.eq("password", businessInfo.getPassword());
            if (password.equals(true)){
                int updatepassword = businessMapper.updatepassword(businessInfo);
                return new CommonResult(2000,"查询成功",updatepassword);
            }
          return new CommonResult(5000,"修改失败",null);
    }


    /**
     * 更改头像
     * @param businessInfo
     * @return
     */
    @Override
    public CommonResult updatepouto(BusinessInfo businessInfo) {
        HttpServletRequest request = WebUtils.getRequest();
        String token = request.getHeader("token");
        Map mp = JSON.parseObject(stringRedisTemplate.opsForValue().get(token), Map.class);
        //System.out.println("================"+mp);
        Map user = (Map) mp.get("user");
        String id = (String) user.get("id");
        businessInfo.setId(id);
        //stringRedisTemplate.delete("businessInfo::"+businessInfo.getId());
        int updateperson = businessMapper.updateById(businessInfo);
        return new CommonResult(2000,"修改头像成功",null);
    }

    /**
     * 审核入驻商家
     * @param businessInfo
     * @return
     */

    @Override
    public CommonResult shopstatus(BusinessInfo businessInfo) {
        int i = businessMapper.updateById(businessInfo);
        return new CommonResult(2000,"修改",i);

    }




}

